$(function() {
	/** ---------------重置----------------- */
	$("#btn_reset").click(function() {
		$("#form_changepw").get(0).reset();
		return false;
	});
	/** ---------------修改密码----------------- */
	var $formchangepw = $("#form_changepw"), $oldpassword = $formchangepw.find("[name=oldpw]"),
	$newpassword = $formchangepw.find("[name=newpw]"),$pwconfirm = $formchangepw.find("[name=pwconfirm]");
	
	$("#btn_confirm_edit").click(function() {
		if($oldpassword.val() ==""||$newpassword.val()==""||$pwconfirm.val()==""){
			alert("密码输入不能为空！");
			return false;
			}
		if($newpassword.val().length<6||$newpassword.val().length>18){
			alert("密码长度需要在6-18位之间,请重新输入！");
			return false;
		    }
		if($newpassword.val().length!=$pwconfirm.val().length){
			alert("两次输入的密码长度不一致！");
			return false;
		    }
		if($newpassword.val()!=$pwconfirm.val()){
			alert("两次输入的密码不一致！");
            return false;
		    }
		$.post(serverURL + "su/modifypw", {"oldpw" : $oldpassword.val(),"newpw" : $newpassword.val()}, function(data) {
			console.log(data);
			if(data.code==0){
				alert("密码修改成功,请重新登陆！");
				window.parent.location.href= getRootPath()+"/su/logout";
			}else if(data.code==109){
				alert("原密码输入错误，请重新输入！");
				window.location.reload() ;
			}	
		});
	});
});
function getRootPath() {
    var strFullPath = window.document.location.href;
    var strPath = window.document.location.pathname;
    var pos = strFullPath.indexOf(strPath);
    var prePath = strFullPath.substring(0, pos);
    var postPath = strPath.substring(0, strPath.substr(1).indexOf('/' ) + 1);
    return (prePath + postPath);
}
